<!DOCTYPE html>
<html>

<head>
  <meta charset="utf-8" />
  <title>用户管理</title>
  <meta name="renderer" content="webkit" />
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1" />
  <link rel="stylesheet" href="../lib/layui-v2.5.5/css/layui.css" media="all" />
  <link rel="stylesheet" href="../css/public.css" media="all" />
</head>
<style>
  td .layui-form-select {
    margin-top: -10px;
    margin-left: -15px;
    margin-right: -15px;
  }
</style>

<body>
  <div class="layuimini-container">
    <div class="layuimini-main">
      <div id="Myloading">
        <img src="../lib/layui-v2.5.5/css/modules/layer/default/loading-01.gif" alt="" />
      </div>
      <script type="text/html" id="toolbarDemo">
          <div class="layui-btn-container">
            <button class="layui-btn layui-btn-sm data-add-btn" lay-event="add">
              添加用户
            </button>
            -->
            <!-- <button class="layui-btn layui-btn-sm layui-btn-danger data-delete-btn" lay-event="delete"> 配置权限 </button>  -->
          </div>
        </script>

      <table class="layui-hide" id="HcurrentTableId" lay-filter="currentTableFilter"></table>

      <script type="text/html" id="currentTableBar">
          <a
            class="layui-btn layui-btn-xs data-count-edit "
            data-title="报警事项"
            lay-event="set"
            >查看</a
          >
          <a
            class="layui-btn layui-btn-xs data-count-edit layui-btn-normal"
            data-title="设备列表"
            lay-event="edit"
            >更新</a
          >
          <a
            class="layui-btn layui-btn-xs data-count-edit layui-btn-danger"
            data-title="报警事项"
            lay-event="delete"
            >删除</a
          >
          <a
            class="layui-btn layui-btn-xs data-count-edit layui-btn-warm"
            data-title="报警事项"
            lay-event="admin"
            >重置密码</a
          >
        </script>
    </div>
  </div>
  <script src="../lib/layui-v2.5.5/layui.js" charset="utf-8"></script>
  <script src="../js/lay-config.js?v=1.0.4" charset="utf-8"></script>
  <script>
    layui.use(["form", "table", "miniTab", "element"], function () {
      // 2020-03-25 HF 保存token
      var token = sessionStorage.getItem("newtoken");
      var login_name = sessionStorage.getItem("SaveLogName");
      var $ = layui.jquery,
        ele = layui.element,
        form = layui.form,
        miniTab = layui.miniTab,
        table = layui.table;
      miniTab.listen();

      table.render({
        elem: "#HcurrentTableId",
        url: "/oms-web/users?token=" + token + "&type=" + "-1",
        // url:'../api/ceshi.json',
        toolbar: "#toolbarDemo",
        parseData: function (res) {
          console.log(res);
          //res 即为原始返回的数据
          return {
            code: res.code, //解析接口状态
            msg: res.msg, //解析提示文本
            count: res.data.total, //解析数据长度
            data: res.data.list, //解析数据列表
          };
        },
        defaultToolbar: [
          "filter",
          "exports",
          "print",
          {
            title: "提示",
            layEvent: "LAYTABLE_TIPS",
            icon: "layui-icon-tips",
          },
        ],

        cols: [
          [
            //复选框 {type: "checkbox", width: 50, fixed: "left"},
            { type: "numbers", width: 120, title: "序号", align: "center" },
            {
              field: "groupName",
              minWidth: 110,
              title: "组别",
              align: "center",
            },
            {
              field: "loginName",
              minWidth: 110,
              title: "账号名称",
              align: "center",
            },
            {
              field: "passwd",
              minWidth: 110,
              title: "密码",
              align: "center",
            },
            {
              field: "typoDesc",
              minWidth: 110,
              title: "权限",
              align: "center",
            },
            {
              field: "userDesc",
              minWidth: 110,
              title: "用户描述",
              align: "center",
            },
            {
              title: "操作",
              width: 250,
              templet: "#currentTableBar",
              fixed: "right",
              align: "center",
            },
          ],
        ],
        limits: [10, 15, 20, 25, 50, 100],
        limit: 15,
        page: true,
        done: function (res) {
          // 表格渲染完成回调
          if (res.code == -1) {
            window.location = "./login-1.html";
          }
          $("#Myloading").remove();
          sessionStorage.setItem("HgroupName", res.data[0].groupName);
        },
      });
      // 监听搜索操作
      form.on("submit(data-search-btn)", function (data) {
        // var result = JSON.stringify(data.field.username);
        // console.log(data);

        // layer.alert(result, {
        //     title: '最终的搜索信息'
        // });

        //执行搜索重载
        table.reload(
          "currentTableId",
          {
            //     page: {
            //         curr: 1
            //     }
            //     , where: {
            //         'text': result
            //     }
          },
          "data"
        );

        return false;
      });

      /**
       * toolbar监听事件
       */
      table.on("toolbar(currentTableFilter)", function (obj) {
        // admin  问题
        // $.ajax({
        //         url: '/oms-web/users/admin?token='+token,
        //         dataType:"json",
        //         type:"get",
        //         async: false,
        //         contentType:"application/json",
        //         success:function(data){
        //             console.log(data);
        //         },
        //         error:function(){
        //             layer.msg('数据出错！')
        //         }
        //     });

        sessionStorage.setItem("Hsee", "55");
        if (obj.event === "add") {
          // 监听添加操作
          var index = layer.open({
            title: "添加用户",
            type: 2,
            shade: 0.2,
            maxmin: true,
            shadeClose: true,
            area: ["40%", "70%"],
            content: "./table/add.html",
          });
          // $(window).on("resize", function () {
          //     layer.full(index);
          // });
        } else if (obj.event === "delete") {
          // 监听删除操作
          // var checkStatus = table.checkStatus('currentTableId')
          //     , data = checkStatus.data;
          // layer.alert(JSON.stringify(data));
          // var index = layer.open({
          //     title: '权限配置',
          //     type: 2,
          //     shade: 0.2,
          //     maxmin:true,
          //     shadeClose: true,
          //     area: ['40%', '70%'],
          //     content: './table/Hconfiguration.html',
          // });
        }
      });

      //监听表格复选框选择
      table.on("checkbox(currentTableFilter)", function (obj) { });

      // 获取列表data
      table.on("tool(currentTableFilter)", function (obj) {
        if (obj.event === "edit") {
          sessionStorage.setItem("Hsee", "57");
          sessionStorage.setItem("HseeName", obj.data.loginName);
          // sessionStorage.setItem('HseeName',JSON.stringify(obj.data.loginName));
          var index = layer.open({
            title: "更新用户",
            type: 2,
            shade: 0.2,
            maxmin: true,
            shadeClose: true,
            area: ["40%", "70%"],
            content: "./table/add.html",
          });
          // $(window).on("resize", function () {
          //     layer.full(index);
          // });
        } else if (obj.event === "delete") {
          layer.confirm(
            "确定删除吗？数据不可恢复！",
            {
              btn: ["确定", "取消"], //按钮
            },
            function () {
              $.ajax({
                url:
                  "/oms-web/users/" + obj.data.loginName + "?token=" + token,
                dataType: "json",
                type: "DELETE",
                contentType: "application/json",
                success: function (data) {
                  if (data.code == -1) {
                    window.location = "./login-1.html";
                  }
                  if (data.code == 0) {
                    layer.msg(
                      "删除用户成功",
                      { icon: 1, time: 1000 },
                      function () {
                        // 如果是当前用户   清空sessionStorage 跳转登录页
                        if (login_name == obj.data.loginName) {
                          sessionStorage.clear();
                          window.location = "./login-1.html";
                        }
                        window.location.reload(); //修改成功后刷新父界面
                      }
                    );
                  } else {
                    layer.msg("删除失败！", { icon: 2 }, function () { });
                  }
                },
                error: function () {
                  layer.msg("数据出错！");
                },
              });
            }
          );
        } else if (obj.event === "admin") {
          sessionStorage.setItem("HseeName", obj.data.loginName);
          var index = layer.open({
            title: "重置密码",
            type: 2,
            shade: 0.2,
            maxmin: true,
            shadeClose: true,
            area: ["30%", "32%"],
            content: "./table/passwd.html",
          });
          // $(window).on("resize", function () {
          //     layer.full(index);
          // });
        } else if (obj.event === "set") {
          sessionStorage.setItem("Hsee", "56");
          sessionStorage.setItem("HseeName", obj.data.loginName);
          var index = layer.open({
            title: "查看用户",
            type: 2,
            shade: 0.2,
            maxmin: true,
            shadeClose: true,
            area: ["40%", "70%"],
            content: "./table/add.html",
          });
          // $(window).on("resize", function () {
          //     layer.full(index);
          // });
        }
      });
    });
  </script>
  <script></script>
</body>

</html>